$(function(){
	common.goBackNext();
	var globalHost=common.globalHost;
	var pointExchange=common.pointExchange;
	var url=globalHost+pointExchange;
	var getVisitPointPort=common.getVisitPointByAgentId;
	var getVisitPointUrl=globalHost+getVisitPointPort;
	var token=common.getToken();
	var agentInfo=common.getLocalData('H5-agentInfo');
	var sendData={
		token:token,
		agentId:agentInfo.id,
	}
	var $currentPoint=$('#currentPoint');
	var $availablePoint=$('#availablePoint');
	var point=0;
	common.requestFormData({
		url:getVisitPointUrl,
		sendData:sendData,
		resSuccess:function (data) {
			var data=data.res.data.record;
			    point=!!data['point']?Number(data['point']):0;
			$currentPoint.html(point);
			$availablePoint.html(point);
        },
        resFailed:function (data) {

        }
	});
	var $getMOneyForm=$('#getMOneyForm');
	var moneyList=[5,10,20,50,100,500];
	var $cashWithdrawal=$('#cash-withdrawal');
	var $alipayAccount=$('#alipay-account');
	var $alipayName=$('#alipay-name');
	baseInfoForm.buildSelectByDataList({selector:$cashWithdrawal,dataList:moneyList,initTitle:"请选择"});
	var $applyWithdrawBtn=$('.apply-withdraw-btn');
	$applyWithdrawBtn.off('tap').on('tap',function(e){
		var $this=$(this);
		var checkCase=$this.hasClass("act-ago");
		var realNameInput=baseInfoForm.testText({targetSelector:$alipayName,noticeMsg:'真实姓名'});
		var accountInput=baseInfoForm.testTextAccount({targetSelector:$alipayAccount,noticeMsg:'支付宝账户'});
		var cashInput=baseInfoForm.testText({targetSelector:$cashWithdrawal,noticeMsg:'提现金额'});
		var cashWithdrawalVal=Number($cashWithdrawal.val());
		if(point>=cashWithdrawalVal){
			var formData=common.getSendDataByForm($getMOneyForm);
			sendData = $.extend({}, sendData, formData);
			if(!!checkCase&&!!realNameInput&&!!accountInput&&!!cashInput){
				$this.removeClass("act-ago").addClass('acted-yet');
				baseInfoForm.formPost({
		    		url:url,
		    		sendData:sendData,
		    		resSuccess:function (data) {
		                $this.removeClass("acted-yet").addClass("act-ago");
		                baseInfoForm.initForm(baseInfoForm.form); 
		                window.location.href='mine.html';
		            },
		            resFailed:function (data) {
		                $this.removeClass("acted-yet").addClass("act-ago");
		            },
		            resError:function(){
		                $this.removeClass("acted-yet").addClass("act-ago");
		            }
		    	})
			}else{
			    console.log("不准发送ajax");
			}
		}else{
			baseInfoForm.changeMsg('亲，提现金额不能多于积分呦')
		}
		
		e.preventDefault();
		return false;
	})
})